{* $Id$ *}
{include_core file="admin/lib/header.html" title="满减促销展示"}
<div class="page-header border-bottom clearfix">
  <h2 class="left">满减促销<span>{if $info}编辑{else}添加{/if}优惠券</span></h2>
  <a href="{AnUrl('coupon/admin')}" class="btn btn-default btn-sm right">&lt;&nbsp;返回活动列表</a>
</div>
<!--start:优惠券新增-->
<div class="add-form">
  <form class="js_creatForm" action="{AnUrl('promotion_sub/admin/save')}" method="post" enctype="multipart/form-data">
    <input type="hidden" name="id" value="{$promotion_info.id}">
    <table class="table" cellpadding="0" cellspacing="0">
      <tr>
        <th><label for="" class="add-f-label">活动标题：</label></th>
        <td>
          <input name="info[title]" style="width:490px;" value="{$promotion_info.title}" type="text" class="add-f-ipt1 js_title">
          <div class="tips"><span style="line-height: 34px;color: #f00;margin-right: 10px;">*</span>活动标题会显示在相应内容的标题位置，最多输入 <span style="color:red;">20</span> 字，还可输入 <span class="js_titleNum" style="color:red;">20</span> 字</div>
        </td>
      </tr>
      <tr>
        <th><label for="" class="add-f-label">使用最低价格：</label></th>
        <td>
          <input name="info[limit_price]" style="width:490px;" value="{$promotion_info.limit_price}" type="text" class="add-f-ipt1 js_number js_offerPrice">
          <div class="tips"><span style="line-height: 34px;color: #f00;margin-right: 10px;">*</span>活动使用最低满足价格, 默认为0</div>
        </td>
      </tr>
      <tr>
        <th><label for="" class="add-f-label">立减价格：</label></th>
        <td>
          <input name="info[offer_price]" style="width:490px;" value="{$promotion_info.offer_price}" type="text" class="add-f-ipt1 js_limitPrice js_number">
          <div class="tips"><span style="line-height: 34px;color: #f00;margin-right: 10px;">*</span>优惠价格是满足条件后立即减少价格</div>
        </td>
      </tr>
      <tr>
        <th><label for="" class="add-f-label">活动时间：</label></th>
        <td>
          <input type="text" class="search-f-ipt1 search-f-ipt2" name="info[start_time]" value="{$promotion_info.start_time}" id="startTime">
          <span class="search-f-line"></span>
          <input type="text" class="search-f-ipt1 search-f-ipt2" name="info[end_time]" value="{$promotion_info.end_time}" id="stopTime">
          <div class="tips"><span style="line-height: 34px;color: #f00;margin-right: 10px;">*</span>选择活动有效日期</div>
        </td>
      </tr>
      <tr><th>&nbsp;</th><td class="noborder"><button type="submit" class="btn btn-success js_submit">&nbsp;&nbsp;&nbsp;确认&nbsp;&nbsp;&nbsp;</button></td></tr>
    </table>
  </form>
</div>
<!--end:优惠券新增-->
{load_js file='zclip/jquery.zclip.min.js'}
{load_js file='zclip/ZeroClipboard.js'}
<script>
  var resName = 'promotion';
  function setNum(thisClass, maxNum) {
    var presentNum = $('.'+thisClass).val().length;
    var remainNum  = maxNum - presentNum;
    if (remainNum < 0) {
      $('.'+thisClass).val($('.'+thisClass).val().substr(0,maxNum));
      $('.'+thisClass+'Num').text(0);
    } else {
      $('.'+thisClass+'Num').text(remainNum);
    }
  }

  $(function(){
    // 初始化剩余字数
    setNum('js_title', 20);
    $('.js_title').keyup(function(){
      setNum('js_title', 20);
    });

    // 输入数字
    $('.js_number').keyup(function(){
      autoNum($(this));
    });

    // 选择时间
    $('#startTime, #stopTime').datepicker({
      dateFormat: 'yy-mm-dd',
      showButtonPanel: true,
      changeYear:true,
      changeMonth:true,
      minDate: '-10y',
      maxDate: '+5y',
      yearSuffix: ''
    });

    // 提交验证
    $('.js_submit').click(function(e){
      e.preventDefault();
      var title      = $.trim($('.js_title').val());
      var offerPrice = $.trim($('.js_offerPrice').val());
      var limitPrice = $.trim($('.js_limitPrice').val());
      var startTime  = $.trim($('#startTime').val());
      var stopTime   = $.trim($('#stopTime').val());

      if (!title) {
        showMsg('标题不能为空');
        return;
      }

      if (!limitPrice) {
        showMsg('优惠条件不能为空');
        return;
      }

      if (!offerPrice) {
        showMsg('立减价格不能为空');
        return;
      }

      if (offerPrice < limitPrice) {
        showConfirm('您优惠的太多了，这样会亏本哦', 1, function(){
          $('.js_creatForm').submit();
        });
        //showMsg('您优惠的太多了，这样会亏本哦');
        return;
      }

      if (startTime > stopTime) {
        showMsg('结束时间应大于等于开始时间');
        return;
      }

      $('.js_creatForm').submit();
    });
  });

  // 自动转为数字
  function autoNum(obj) {
    var currNum = obj.val();
    currNum = parseInt(currNum);
    if (isNaN(currNum)) {
      currNum = '';
    };
    obj.val(currNum);
  }
</script>
{include_core file="admin/lib/footer.html"}